<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>迭代器模式</title>
</head>
<body>
    <script>
        var store = {
            data: {
                map: {},
                list: []
            },
            get(id) {
                return this.data.map[id]
            },
            push(val) {
                this.data.map[val.id] = val
                this.data.list.push(val)
            },
            each(fn) {
                this.data.list.forEach(function(item) {
                    fn(item)
                })
            }
        }

        var list = [
            {
                id: 'aa-xx-dd',
                title:'冬季羽绒服-女士'
            },
            {
                id: 'aa-xx-333',
                title:'冬季羽绒服-男士'
            },
        ]
        
        store.push(list[0])
        store.push(list[1])

        console.log(
            store.get('aa-xx-333')
        )
        store.each(function(item) {
            console.log(item)
        })



    </script>
</body>
</html>